//
//  HZNoticeViewController.m
//  HZTC_YaDeArt
//
//  Created by MayerF on 17/3/21.
//  Copyright © 2017年 HZTC. All rights reserved.
//

#import "HZNoticeViewController.h"
#import "HZNoticeView.h"
//#import "HZWebViewController.h"
#import "NSString+NormalTool.h"

@interface HZNoticeViewController ()
@property(nonatomic,strong)HZNoticeView   *pNoticeView;
@end

@implementation HZNoticeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"公告";
    
    _pNoticeView = [HZNoticeView new];
    
    __weak typeof (self)weakSelf = self;
    _pNoticeView.actionClickList = ^(NSDictionary *dict, id other, ActionBack actionBack){
        [weakSelf p_goNoticeDetailWithId:other];
    };
    
    [self.view addSubview:_pNoticeView];
    [self p_initConstraints];
}

- (void)viewWillAppear:(BOOL)animated{
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [self p_sendNoticeRequest];
}

#pragma mark -
#pragma mark private
- (void)p_initConstraints
{
    [_pNoticeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}
#pragma mark -
#pragma mark request
- (void)p_goNoticeDetailWithId:(HZNoticeModel *)notice
{
    NSString *IP = [kAPIHost substringToRelatedString:@"/client"];
    NSString *url = [NSString stringWithFormat:@"%@/client/static/notice.html?notice_id=%@&type=%@",IP, notice.notice_id, notice.type];
    
    UIViewController *nextVC = [[MYRouter shared] matchController:kRouterLoadWeb params:@{@"url": url, @"title": @"公告"}];
    [self.navigationController pushViewController:nextVC animated:YES];
}
#pragma mark -
#pragma mark request
- (void)p_sendNoticeRequest{
    [SVProgressHUD show];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"000003", kAPIFuctionKey,
                          @"",@"notice_id",
                          @"",@"startdate",
                          @"",@"enddate",
                          nil];
    [HZApiManager apiPostParams:dict success:^(id objc) {
        if ([objc isKindOfClass:[NSArray class]]) {
            NSMutableArray *tempArray = [NSMutableArray array];
            for (NSDictionary *dict in objc) {
                HZNoticeModel *pNoticeModel = [HZNoticeModel mj_objectWithKeyValues:dict];
                [tempArray addObject:pNoticeModel];
            }
            [_pNoticeView setNoticeData:tempArray];
        }else {
            [_pNoticeView setNoticeData:nil];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:error.domain];
    }];
}

@end
